<template>
    <el-menu :default-active="activeIndex2" class="el-menu-demo" mode="horizontal" background-color="#545c64"
        text-color="#fff" active-text-color="#ffd04b" router @select="handleSelect">
        <el-menu-item route="/" index="1">首页</el-menu-item>
        <el-sub-menu index="2">
            <template #title>Workspace</template>
            <el-menu-item index="2-1" route="#">item one</el-menu-item>
            <el-menu-item index="2-2" route="#">item two</el-menu-item>
            <el-menu-item index="2-3" route="#">item three</el-menu-item>
        </el-sub-menu>
        <el-menu-item index="3" route="#">商城</el-menu-item>
        <template v-if="isLogin">
            <el-menu-item index="6" route="/create">创作</el-menu-item>
            <el-menu-item index="5" route="/mine">我的</el-menu-item>
        </template>
        <template v-else>
            <el-menu-item index="8" route="#" disabled>注册</el-menu-item>
            <el-menu-item index="4" route="#" @click="login">登录</el-menu-item>
        </template>
    </el-menu>
</template>
  
<script lang="ts" setup>
import { ref } from 'vue'
import { storeToRefs } from 'pinia'
import { useCounterStore } from '@/stores/counter'
import { useStore } from '@/stores/user'

const store = useCounterStore();
const useInfoStore = useStore()

const { isLogin } = storeToRefs(useInfoStore)
const activeIndex2 = ref('1')
const handleSelect = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
const login = () => {
    store.setDialogState(true)
}
</script>
  